package com.edu.controller;

import com.edu.bean.Book;
import com.edu.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:何包蛋
 * @Date :2022/11/20 - 11 - 20 - 16:48
 */
@Controller
public class BookController {

    @Resource
    private BookService bookService;

    @RequestMapping("/book")
    public String getAllBook(Model model){
        List<Book> books = bookService.getAllBook();
        model.addAttribute("books",books);
        return "success.jsp";
    }

    @GetMapping("/book/{bookid}")
    public String getBookById(@PathVariable("bookid") int bookid , Model model){
        Book book = bookService.getById(bookid);
        model.addAttribute("book",book);
        return "/book.jsp";
    }
}
